package com.yic.module.base.dal.mysql.unit;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.unit.UnitDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.unit.vo.*;

/**
 * 单位 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface UnitMapper extends BaseMapperX<UnitDO> {

    default PageResult<UnitDO> selectPage(UnitPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UnitDO>()
                .likeIfPresent(UnitDO::getName, reqVO.getName())
                .eqIfPresent(UnitDO::getCode, reqVO.getCode())
                .orderByDesc(UnitDO::getId));
    }

    default List<UnitDO> selectList(UnitExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UnitDO>()
                .likeIfPresent(UnitDO::getName, reqVO.getName())
                .eqIfPresent(UnitDO::getCode, reqVO.getCode())
                .orderByDesc(UnitDO::getId));
    }

    default UnitDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<UnitDO>()
                .eqIfPresent(UnitDO::getName, name));
    }

    default UnitDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<UnitDO>()
                .eqIfPresent(UnitDO::getCode, code));
    }

    default List<UnitDO> selectByIds(Collection<Long> ids) {
        return selectList(new LambdaQueryWrapperX<UnitDO>()
                .inIfPresent(UnitDO::getId, ids));
    }

    default UnitDO selectByErpId(String erpUnitId) {
        return selectOne(new LambdaQueryWrapperX<UnitDO>()
                .eq(UnitDO::getRemark, erpUnitId));
    }

    default List<UnitDO> selectListByErpId(Collection<String> erpUnitIds) {
        return selectList(new LambdaQueryWrapperX<UnitDO>()
                .inIfPresent(UnitDO::getRemark, erpUnitIds));
    }
}
